
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
eth-json-rpc-errors
Advanced tools
Errors for JSON RPC 2.0 and ETH JSON RPC.
CloseEvent
errors or status codes.Installation: npm install eth-json-rpc-errors
Import using ES6 syntax (no default) or Node require
.
import { errors as rpcErrors } from 'eth-json-rpc-errors'
// standard JSON RPC 2.0 errors namespaced directly under rpcErrors
response.error = rpcErrors.methodNotFound(
optionalCustomMessage, optionalData
)
// ETH JSON RPC errors namespaced under rpcErrors.eth
response.error = rpcErrors.eth.unauthorized(
optionalCustomMessage, optionalData
)
// the message can be falsy or a string
// a falsy message will produce an error with a default message
response.error = rpcErrors.eth.unauthorized(null, optionalData)
// omitting the data argument will produce an error without a
// "data" property
response.error = rpcErrors.eth.unauthorized(optionalCustomMessage)
// both arguments can be omitted for almost all errors
response.error = rpcErrors.eth.unauthorized()
response.error = rpcErrors.methodNotFound()
// the JSON RPC 2.0 server error requires a valid code
response.error = rpcErrors.server(
-32031, optionalCustomMessage, optionalData
)
// there's an option for custom ETH errors
// it requires a valid code and a string message
// valid codes are integers i such that: 1000 <= i <= 4999
response.error = rpcErrors.eth.custom(
1001, requiredMessage, optionalData
)
/**
* TypeScript interfaces
*/
import {
IRpcErrors, IJsonRpcError, IEthJsonRpcError, ISerializeError
} from 'eth-json-rpc-errors/@types'
/**
* Classes
*/
import { JsonRpcError, EthJsonRpcError } from 'eth-json-rpc-errors'
/**
* serializeError
*/
// this is useful for ensuring your errors are standardized
import { serializeError } from 'eth-json-rpc-errors'
// if the argument is not a valid error per any supported spec,
// it will be added as error.data.originalError
response.error = serializeError(maybeAnError)
// you can add a custom fallback error code and message if the
const fallbackError = { code: 4999, message: 'My custom error.' }
response.error = serializeError(maybeAnError, fallbackError)
// the default fallback is:
{
code: -32603,
message: 'Internal JSON-RPC error.'
}
/**
* getMessageFromCode & ERROR_CODES
*/
import { getMessageFromCode, ERROR_CODES } from 'eth-json-rpc-errors'
// get the default message string for the given code, or a fallback message if
// no message exists for the given code
const message1 = getMessageFromCode(someCode)
// you can specify your own fallback message
const message2 = getMessageFromCode(someCode, myFallback)
// it can be anything, use at your own peril
const message3 = getMessageFromCode(someCode, null)
// {
// jsonRpc: { [errorName]: code, ... },
// eth: { [errorName]: code, ... },
// }
const code1 = ERROR_CODES.jsonRpc.parse
const code2 = ERROR_CODES.eth.userRejectedRequest
// all codes in ERROR_CODES have default messages
const message4 = getMessageFromCode(code1)
const message5 = getMessageFromCode(code2)
MIT
FAQs
Ethereum JSON RPC and Provider errors.
The npm package eth-json-rpc-errors receives a total of 11,562 weekly downloads. As such, eth-json-rpc-errors popularity was classified as popular.
We found that eth-json-rpc-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.